//
//  UIImage+Extension.swift
//  SainMicroblog
//
//  Created by chenxinju on 16/5/10.
//  Copyright © 2016年 chenxinju-a2. All rights reserved.
//

import UIKit


//获取当前屏幕截图的方法
extension UIImage {
    
    class func getScreenShot() ->UIImage {
        //1.获取window
        let window = UIApplication.sharedApplication().keyWindow
        //2.开始绘制  size:大小 opaue：透明度 scale:缩放
        UIGraphicsBeginImageContextWithOptions(WBUIScreenBounds.size, false, 1)
        //3.让window进行绘画
        window?.drawViewHierarchyInRect(WBUIScreenBounds, afterScreenUpdates: false)
        //4.获取image
        let image = UIGraphicsGetImageFromCurrentImageContext()
        
        //5 关闭绘画
        UIGraphicsEndImageContext()
        
        return image
    }
    //选择系统图片绘制
    class func getScalImage(image:UIImage) ->UIImage {
        
        let size = image.size
        if size.width > 300 {
            
            let width = 300
            let height = size.height * (size.width / 300)
            
        }
        //开启上下文
        UIGraphicsBeginImageContext(image.size)
        
        //绘画
        image.drawAsPatternInRect(CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height))
        //获取图片
        let img =  UIGraphicsGetImageFromCurrentImageContext()
        //关闭上下文
        UIGraphicsEndImageContext()
        //返回
        return img
        
    }
}